package com.kkd.kkdapp.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.activity.CheckMainUrlActivity;
import com.kkd.kkdapp.base.MyBaseAdapter;
import com.kkd.kkdapp.http.entity.TwoFriendsDataList;
import com.kkd.kkdapp.view.RoundImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class TwoFriendsAdapter extends MyBaseAdapter<TwoFriendsDataList> {

	private List<TwoFriendsDataList> dataList;

	public TwoFriendsAdapter(Context context) {
		super(context);
		dataList = this.getAdapterData();
	}

	@Override
	public View getMyView(final int position, View convertView, ViewGroup parent) {
		ViewHolder mViewHolder;
		if (convertView == null) {
			convertView = View
					.inflate(context, R.layout.two_friends_item, null);
			mViewHolder = new ViewHolder();
			mViewHolder.userphone = (TextView) convertView
					.findViewById(R.id.userphone);
			mViewHolder.username = (TextView) convertView
					.findViewById(R.id.username);
			mViewHolder.time = (TextView) convertView.findViewById(R.id.time);
			mViewHolder.friend = (TextView) convertView
					.findViewById(R.id.friend);
			mViewHolder.head = (RoundImageView) convertView
					.findViewById(R.id.head);
			convertView.setTag(mViewHolder);
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}
		mViewHolder.userphone.setTag(position);
		mViewHolder.userphone.setText(dataList.get(position).getCustomerName());
		mViewHolder.username.setTag(position);
		mViewHolder.username.setText(dataList.get(position)
				.getCustomerRealname());
		mViewHolder.time.setTag(position);
		mViewHolder.time.setText("注册时间：" + dataList.get(position).getAddDate());
		mViewHolder.friend.setTag(position);
		mViewHolder.friend.setText(dataList.get(position).getAmount());
		mViewHolder.head.setTag(position);
		mViewHolder.head.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, CheckMainUrlActivity.class);
				intent.putExtra("mode", "1");
				intent.putExtra("url", dataList.get(position).getUserHeadUrl());
				context.startActivity(intent);
				((Activity)context).overridePendingTransition(R.anim.zoomin, R.anim.zoomout);	
			}
		});
//		ImageCache.getInstance(context).displayImage(mViewHolder.head,
//				dataList.get(position).getUserHeadUrl(),
//				R.drawable.myrecommendfriend_head);
		ImageLoader.getInstance().displayImage(dataList.get(position).getUserHeadUrl(), mViewHolder.head);
		return convertView;
	}

	class ViewHolder {
		TextView userphone;
		TextView username;
		TextView time;
		TextView friend;
		RoundImageView head;
	}

}
